<template>
  <div
    class="swiper-container"
    @mouseenter="swiper.autoplay.stop()"
    @mouseleave="swiper.autoplay.start()"
    ref="swiper"
  >
    <div class="swiper-wrapper">
      <div
        class="swiper-slide"
        v-for="(img, index) in this.imageList"
        :key="index"
      >
        <img v-bind:src="img.imgUrl" />
      </div>
    </div>
    <!-- Add Arrows -->
    <div class="swiper-button-next"></div>
    <div class="swiper-button-prev"></div>
    <!-- Add Pagination -->
    <div class="swiper-pagination"></div>
  </div>
</template>

<script>
import Swiper from "swiper";
import "swiper/css/swiper.min.css";

export default {
  name: "Carousel",
  props: {
    imageList: Array,
  },
  watch: {
    imageList: {
      handler(imageList) {
        if (!imageList.length) return;
        if(imageList.length===3)console.log(1);
        if(imageList.length===4)console.log(2);
        this.$nextTick(() => {
          this.swiper = new Swiper(this.$refs.swiper, {
            navigation: {
              // 左右箭头
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },
            pagination: {
              // 小圆点
              el: ".swiper-pagination",
            },
            loop: true, // 无缝轮播
            autoplay: {
              // 自动轮播
              delay: 1000,
            },
            loopPreventsSlide:true
          });
        });
      },
      immediate: true,
    },
  },
};
</script>

<style>
</style>